
clear all

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"
local path1="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\outregs"

capture cd "`path0'Workfiles"
set more off
use completed_data, clear


	* create settler mortality with the African data corrected based on Albouy
	capture drop logmort3
	gen logmort3=logmort2
	replace logmort3=logmort if countrycode=="SGP" | countrycode=="AUS"
	
	gen lnUKdist=log(geo_UK_distw)

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 			Table 2: basic IV and OLS regressions
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*===============	Panel A: output per worker ================================
	*** OLS
	reg pwt_ln_rgdpwok idv, robust 
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		replace bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 

	xi: reg pwt_ln_rgdpwok idv i.continent , robust 
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: cont") 

	xi: reg pwt_ln_rgdpwok idv  barro_prot_70-barro_nonrel_70	landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: muslim") 		
	
	xi: reg pwt_ln_rgdpwok idv i.continent  barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: all") 	
		

	*** IV	
	ivreg2 pwt_ln_rgdpwok (idv = distM_UK), robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	
	xi: ivreg2 pwt_ln_rgdpwok i.continent (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: cont") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
	
	xi: ivreg2 pwt_ln_rgdpwok barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: muslim") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
		
	xi: ivreg2 pwt_ln_rgdpwok i.continent barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002A.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: all") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	
	
	*================== Panel B: Hall and Jones (QJE 1999) ===========================
	*** OLS
	reg hjtfp idv if continent~=., robust 
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		replace bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 

	xi: reg hjtfp idv i.continent , robust 
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: cont") 

	xi: reg hjtfp idv barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: muslim") 		
	
	xi: reg hjtfp idv i.continent barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: all") 	
		

	*** IV	
	ivreg2 hjtfp (idv = distM_UK)  if continent~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	
	xi: ivreg2 hjtfp i.continent (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: cont") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
	
	xi: ivreg2 hjtfp barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: muslim") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
		
	xi: ivreg2 hjtfp i.continent barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002B.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: all") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
		
	
	*================== Panel C: Log patents per capita ========================
	capture drop ln_eiu_ppm
	gen ln_eiu_ppm=log(eiu_ppm)	
	*** OLS
	reg ln_eiu_ppm idv if continent~=., robust 
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		replace bdec(3) rdec(3) aster nocons nolabel ctitle("OLS") 

	xi: reg ln_eiu_ppm idv i.continent , robust 
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: cont") 

	xi: reg ln_eiu_ppm idv barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: muslim") 		
	
	xi: reg ln_eiu_ppm idv i.continent barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati , robust 
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("OLS: all") 	
		

	*** IV	
	ivreg2 ln_eiu_ppm (idv = distM_UK) if continent~=., robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
	
	xi: ivreg2 ln_eiu_ppm i.continent (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: cont") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
	
	xi: ivreg2 ln_eiu_ppm barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: muslim") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
		
	xi: ivreg2 ln_eiu_ppm i.continent barro_prot_70-barro_nonrel_70 landlocked abs_long abs_lati (idv = distM_UK) , robust ffirst
	matrix A=e(first)
	local R2first=A[2,1]
	local Ffirst =A[3,1]
	outreg2 idv using "`path1'\RR_table002C.txt" , ///
		append bdec(3) rdec(3) aster nocons nolabel ctitle("IV: all") ///
		addstat("1st stage F-stat", `Ffirst',"Partial R2",`R2first')
		
